package com.bestv.origin.controller;

import java.io.IOException;
import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bestv.origin.entity.Testobj;

@Controller
@RequestMapping("/testController")
public class GeneralController {

	@RequestMapping(params = "test")
	public ModelAndView index_jsp(HttpServletRequest req, Model model) {
		// req.setAttribute("liming", "黎明你好");
		Testobj testobj = new Testobj();
		// testobj.setA("123");
		// testobj.setB("456");
		model.addAttribute("testobj", testobj);
		System.out.println("done.");
		return new ModelAndView("index");
	}

	@RequestMapping(params = "datagrid")
	public void datagrid(HttpServletRequest req, HttpServletResponse res) {
		try {
			List<Testobj> userlist = new ArrayList();
			Testobj testobj = new Testobj();
			testobj.setFirstname("sj");
			testobj.setLastname("fan");
			testobj.setPhone("138xxx");
			testobj.setEmail("xx@qq.com");
			userlist.add(testobj);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("total", userlist.size());
			map.put("rows", userlist);
			JSONObject jsonobj = JSONObject.fromObject(map);
			res.getWriter().write(jsonobj.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
